package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
	"strings"
)

func main(){
	fmt.Println("认证请求RestFul的接口数据")
	fmt.Println(HttpGet("www.baidu.com"))





}


func HttpGet(uri string)string{
	resp,err:= http.Get(uri)
	if err != nil{
		return "err"
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil{
		return "err"
	}
	return string(body)
}

func HttpPost(uri string, param string, mime string) string{
	resp, err := http.Post(uri, mime, strings.NewReader(param))
	if err != nil{
		return string(err)
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil{
		return string(err)
	}
	return string(body)
}
